package com.atguigui.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

/**
 * 1656.设计有序流
 * Project: leetcode
 * Package: com.atguigui.leetcode
 * Version: 1.0
 * <p>
 * Created by WJX on 2022/8/16 8:37
 */
public class P1656DesignAnOrderedStream {
    public static void main(String[] args) {
        OrderedStream solution = new P1656DesignAnOrderedStream().new OrderedStream(3);
        // TO TEST
    }

    class OrderedStream {

        private String nums[];
        private int ptr = 0;

        public OrderedStream(int n) {
            this.nums = new String[n];
            Arrays.fill(this.nums, "");
        }

        public List<String> insert(int idKey, String value) {
            nums[idKey - 1] = value;
            List<String> ans = new ArrayList<>();
            if ("".equals(nums[ptr])) {
                return ans;
            } else {
                while (ptr <= nums.length - 1 && !"".equals(nums[ptr])) {
                    ans.add(nums[ptr]);
                    ptr++;
                }
                return ans;
            }
        }
    }
}
